package app_demo.io;

import org.junit.Test;

import java.io.*;

/**
 * @Description
 * @Author Firenut
 * @Date 2023-02-05 16:58
 */
public class ReaderTest {
    @Test
    public void test() {
        copyFile("hello.txt");
    }


    public void copyFile(String fileName) {
        BufferedReader br = null;
        BufferedWriter bw = null;
        try {
            br = new BufferedReader(new FileReader(fileName));
            bw = new BufferedWriter(new FileWriter("hello1.txt"));
            String str;
            while ((str = br.readLine()) != null) {
                bw.write(str);
                bw.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if (br != null) {
                    br.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if (bw != null) {
                    bw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
